# -*- coding: utf-8 -*-
import os

from datetime import datetime
import csv


# 导出的详细信息
def append_export_data(export_data, new_controller_name, new_method_name, diff_type, diff_info):
    export_data['Controller名称'].append(os.path.basename(new_controller_name))
    export_data['方法名称'].append(new_method_name)
    export_data['不兼容类型'].append(diff_type.value)
    export_data['详细信息'].append(diff_info)


def export_csv(export_data):
    # 将数据转换为DataFrame
    current_datetime = datetime.now()
    formatted_datetime = current_datetime.strftime('%Y-%m-%d_%H-%M-%S')
    csv_file_name = f'springboot_compare_app_warning_{formatted_datetime}.csv'
    # 将数据转换为DataFrame
    with open(csv_file_name, 'w', newline='', encoding='utf-8') as csvfile:
        # 创建CSV写入器
        csv_writer = csv.writer(csvfile)

        # 写入CSV文件标题行（列名）
        csv_writer.writerow(export_data.keys())

        # 写入CSV文件数据行
        # 使用zip将每个列表的相应元素合并成元组
        for row in zip(*export_data.values()):
            csv_writer.writerow(row)
